package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.Partner;
import com.heima.pojo.dto.PagePartnerDto;
import com.heima.pojo.dto.PartnerDTO;
import com.heima.pojo.vo.PartnerVo;
import com.heima.service.PartnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
@Slf4j
public class PartnerController {

    @Autowired
    PartnerService partnerService;

    /**
     * 新增
     */
    @PostMapping
    public Boolean savePartner(@RequestBody PartnerDTO partnerDTO) {
        Boolean isTrue = partnerService.savePartner(partnerDTO);
        return isTrue;
    }

    /**
     * 分页查询
     */
    @GetMapping("/search")
    public PageResult<Partner> searchSku(PagePartnerDto pagePartnerDto) {
        PageResult<Partner> search = partnerService.searchPartner(pagePartnerDto);
        return search;
    }

    /**
     * 获取合作商详情
     */
    @GetMapping("/{id}")
    public PartnerVo getPartner(@PathVariable Long id) {
        PartnerVo partnerVo = partnerService.getPartner(id);
        return partnerVo;
    }

    /**
     * 修改合作商
     */
    @PutMapping("/{id}")
    public Boolean updatePartner(@PathVariable Integer id, @RequestBody PartnerDTO partnerDTO) {
        partnerDTO.setId(id);
        Boolean isTrue = partnerService.updatePartner(partnerDTO);
        return isTrue;
    }

    /**
     * 根据id删除合作商
     */
    @DeleteMapping("/{id}")
    public Boolean deletePartner(@PathVariable Integer id) {
        Boolean isTrue = partnerService.deletePartner(id);
        return isTrue;
    }
}
